/*
 *  NinjaCat.cpp
 *  Untitled
 *
 *  Created by Guo Wei Tan on 1/20/14.
 *  Copyright 2014 __MyCompanyName__. All rights reserved.
 *
 */

#include "NinjaCat.h"
#include "Cats/CatSpriteLoader.h"
#include "Cats/CatStates/CatState_Base_Chase.h"
#include "Cats/CatStates/CatState_Base_Obstacle.h"
#include "Cats/CatStates/CatState_Base_Attack.h"
#include "Cats/CatStates/CatState_Base_Flank.h"
#include "Cats/CatStates/CatState_Ninja_Skill.h"
#include "Cats/CatStates/CatState_Base_Injured.h"
#include "Cats/CatStates/CatState_Base_Dying.h"
#include "Cats/CatStates/CatState_Base_Dead.h"

#include "Character/Character.h"
#include "Map/GameMap.h"
//========================== C O N S T R U C T O R ==============================
NinjaCat::NinjaCat(): BaseCat()
{
	//BASE VALUES
	//animation
	RECT_BUFFER_RADIUS = 20;
	//movement
	VARYING_SPEED = 20;
	BASE_SPEED = 180;
	BASE_SPEED_MULTIPLIER = 1;
	//attack
	BASE_ATTACK_RANGE_GRID = 3;
	BASE_ATTACK_DAMAGE = 1;
	BASE_ATK_SPEED = BASE_SPEED * 2;

	//obstacle/stop
	BASE_OBSTACLE_HIT_CHANCE = 10; //no obstacle hit chance
	SLOW_SPEED_MULTIPLIER = 2;
	SLOW_DURATION = 4;

	//jump
	BASE_JUMP_HEIGHT = 30;
	BASE_JUMP_SPEED = BASE_SPEED;

	//skill
	SKILL_AVAILABLE = false;
	BASE_SKILL_COOLDOWN = 10;
	//health
	BASE_HEALTH = 2;
	//cat type
	CAT_TYPE = NINJA_CAT;

	setImmunity(INJURY_WIND, INJURY_BURNT);
}

/*!
    @function initStates
    @result		initialize the states of the cat.
    			TO BE OVERRIDEN BY CHILDREN CLASSES
 */
void NinjaCat::initStates()
{
	_myCatStates = new CatState*[CAT_STATE_NUM];
	_myCatStates[CAT_CHASE] = new CatState_Base_Chase(this);
	_myCatStates[CAT_OBSTACLE] = new CatState_Ninja_Skill(this);
	_myCatStates[CAT_ATTACK] = new CatState_Base_Attack(this);
	_myCatStates[CAT_FLANK] = new CatState_Base_Flank(this);
	_myCatStates[CAT_SKILL] = new CatState_Ninja_Skill(this);
	_myCatStates[CAT_INJURED] = new CatState_Base_Injured(this);
	_myCatStates[CAT_DYING] = new CatState_Base_Dying(this);
	_myCatStates[CAT_DEAD] = new CatState_Base_Dead(this);

	_myCatStates[CAT_CHASE]->onEnter();
	_currentCatState = CAT_CHASE;
	_previousCatState = CAT_CHASE;
}

/*!
    @function createCat
    @result		returns a cat with loaded sprites
 */
NinjaCat* NinjaCat::createCat()
{
	NinjaCat *cat = new NinjaCat();

	if( cat && cat->initWithSpriteFrame(CatSpriteLoader::getSpriteFrame(cat->getCatType())))
	{
		cat->setScale(GameMap::getInstance()->getScaleFactor());
		cat->initCat();
		cat->autorelease();
		return cat;
	}

	CC_SAFE_DELETE(cat);
	return NULL;
}

void NinjaCat::initCat()
{
	BaseCat::initCat();

	//overrides skill ready
	_skillReady = true;
}

void NinjaCat::reduceHealth(int healthReduction, EnumCatInjury injuryType)
{
	//if cat is in non-touchable state, exit function
	if (_currentCatState == CAT_INJURED || isDead() || _currentCatState == CAT_SKILL)
		return;

	//use skill if skill is ready
	if (_skillReady)
	{
		//set to invulnerable and use blink skill
		startCoolDownTimer();
		setNextCatState(CAT_SKILL);
	}
	else
		BaseCat::reduceHealth(healthReduction, injuryType);

}



